package com.gxa.service.Impl;

import com.gxa.common.R;
import com.gxa.mapper.EmpMapper;
import com.gxa.pojo.Emp;
import com.gxa.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired(required = false)
    private EmpMapper empMapper;

    @Override
    public R queryAll(Integer page,Integer limit) {
        R r = new R();
        Integer param1 = (page - 1)*limit;
        Integer param2 = limit;
        List<Emp> empList = empMapper.queryAll(param1,param2);
        r.setCode(200);
        r.setMsg("查询成功");
        r.setData(empList);
        return r;
    }

    @Override
    public R queryWorking(Integer EMP_QUIT,Integer page,Integer limit) {
        R r = new R();
        Integer param1 = (page - 1)*limit;
        Integer param2 = limit;
        List<Emp> empList = empMapper.queryWorking(EMP_QUIT,param1,param2);
        r.setCode(200);
        r.setMsg("查询成功");
        r.setData(empList);
        return r;
    }

    @Override
    public R addEmp(Emp emp) {
        R r = new R();
        try {
            int result =empMapper.addEmp(emp);
            if(result > 0){
                r.setCode(200);
                r.setMsg("添加员工成功");
            }
        } catch (SQLException e) {
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("系统出错，请联系管理员");
        }
        return r;
    }

    @Override
    public R importEmp() {
        return null;
    }

    @Override
    public R exportEmp() {
        return null;
    }

    @Override
    public R editEmp(Emp emp) {
        R r = new R();
        try {
            int result =empMapper.editEmp(emp);
            if(result > 0){
                r.setCode(200);
                r.setMsg("编辑员工成功");
            }
        } catch (SQLException e) {
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("系统出错，请联系管理员");
        }
        return r;
    }

    @Override
    public R setWorkingToDeparture() {
        return null;
    }

    @Override
    public R setDepartureToBlackList() {
        return null;
    }

    @Override
    public R setBlackListToDeparture() {
        return null;
    }

    @Override
    public R queryEmpDetails() {
        return null;
    }
}
